/*
 * Created by JFormDesigner on Tue Apr 17 15:43:55 EEST 2012
 */

package tr.gov.tubitak.bilgem.esya.crlviewer;

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

/**
 * @author Haydar Karabas
 */
public class ECrlGeneralInfoPanel extends JPanel {
    private EViewerCRL viewerCRL;
    ECrlFieldsModel crlFieldTableModel;

    public ECrlGeneralInfoPanel(EViewerCRL viewerCRL) {
        initComponents();
        this.viewerCRL = viewerCRL;
        initGUI();
        loadCRL();
    }

    void  initGUI()
    {
        ListSelectionModel selectionModel = eCrlFieldsTable.getSelectionModel();
        selectionModel.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int selectedRow = eCrlFieldsTable.getSelectedRow();
                int modelIndex = eCrlFieldsTable.convertRowIndexToModel(selectedRow);
                ECrlField rowField = crlFieldTableModel.getRowField(modelIndex);
                txtDetail.setText(rowField.getValue());
            }
        });
    }

    void loadCRL(){
        crlFieldTableModel = new ECrlFieldsModel();
        eCrlFieldsTable.setModel(crlFieldTableModel);
        crlFieldTableModel.loadFields(viewerCRL);
        eCrlFieldsTable.setRowSelectionInterval(0, 0);
        TableColumnModel columnModel = eCrlFieldsTable.getColumnModel();
        TableColumn column = columnModel.getColumn(0);
        if(column!=null)
        {
            column.setWidth(10);
            column.setPreferredWidth(10);
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("tr.gov.tubitak.bilgem.esya.crlviewer.lang");
        lblCrlTitle = new JLabel();
        scrollPane1 = new JScrollPane();
        eCrlFieldsTable = new ECrlFieldsTable();
        lblDetail = new JLabel();
        scrollPane2 = new JScrollPane();
        txtDetail = new JTextArea();

        //======== this ========
        setLayout(new GridBagLayout());
        ((GridBagLayout)getLayout()).columnWidths = new int[] {10, 0, 10, 0};
        ((GridBagLayout)getLayout()).rowHeights = new int[] {10, 0, 10, 0, 5, 0, 120, 10, 0};
        ((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 1.0, 0.0, 1.0E-4};
        ((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

        //---- lblCrlTitle ----
        lblCrlTitle.setText(bundle.getString("ECRLDialog.sertifikaiptallistesi"));
        lblCrlTitle.setIcon(new ImageIcon(getClass().getResource("/tr/gov/tubitak/bilgem/esya/crlviewer/images/crl.png")));
        lblCrlTitle.setFont(lblCrlTitle.getFont().deriveFont(lblCrlTitle.getFont().getStyle() | Font.BOLD, lblCrlTitle.getFont().getSize() + 1f));
        add(lblCrlTitle, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(eCrlFieldsTable);
        }
        add(scrollPane1, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));

        //---- lblDetail ----
        lblDetail.setText(bundle.getString("ECrlGeneralInfoPanel.detay"));
        lblDetail.setFont(lblDetail.getFont().deriveFont(lblDetail.getFont().getStyle() | Font.BOLD, lblDetail.getFont().getSize() + 1f));
        add(lblDetail, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));

        //======== scrollPane2 ========
        {
            scrollPane2.setViewportView(txtDetail);
        }
        add(scrollPane2, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0), 0, 0));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel lblCrlTitle;
    private JScrollPane scrollPane1;
    private ECrlFieldsTable eCrlFieldsTable;
    private JLabel lblDetail;
    private JScrollPane scrollPane2;
    private JTextArea txtDetail;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
